"""
    @Author  ：思念 
    @File    ：9.使用线程方式爬取豆瓣250.py
    @Date    ：2025/1/5 19:10 
"""

import requests
import threading
from lxml import etree

url = 'https://movie.douban.com/top250?start={}&filter='

headers = {
    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
}

def get_html(page):
    response = requests.get(url.format(page * 25), headers=headers)
    tree = etree.HTML(response.text)
    result = tree.xpath("//div[@class='hd']/a/span[1]/text()")
    print(result)

if __name__ == '__main__':
    thread_list = [threading.Thread(target=get_html, args=(page,)) for page in range(10)]
    for thread in thread_list:
        thread.start()
